<?php
?>
<thead>
<?php
include '../../functions.php';
include '../../additionalFunctions.php';

$crop = $_GET['crops'];
$unit = substr($crop, strripos($crop, " - ") + 3); // gets just the name of the unit
$crop = substr($crop, 0, strripos($crop, " - ")); // finds the last position of occurence of " - " ==> takes only the crop name, not the units
$year = $_GET['year'];
$attributes = $_GET['attributes'];
$attributesArray = explode(';',$attributes);

print "<tr><th></th><th>Month</th>";
foreach ($attributesArray as $a) {
	if ($a == "amount_harvested") 
		print "<th>Amount Harvested</th>";
	else if ($a == "amount_donated") 
		print "<th>Amount Donated</th>";
	else if ($a == "sales") 
		print "<th>Sales</th>";
	else
		print "<th>$a</th>";
}
print "</tr></thead><tbody>";
for ($i = 1; $i <= 12; $i++) {
	$result = array();
	for ($k = 0; $k < count($attributesArray); $k++) {
		$result[$k] = getRangeData($year."-".$i."-01",$year."-".$i."-".lastDayOfMonth($i),getCropId($crop),$attributesArray[$k], getUnitId($unit), $attributesArray[$k] == 'sales' ? getCustomerId($_GET['customers']) : ($attributesArray[$k] == 'amount_donated' ? getCustomerId($_GET['donationCustomers']) : NULL));
	}
	print "<tr><td width=\"25\" id=\"td1\"><img id=\"".getMonth($i)."\" src=\"DataTables-1.7.3/details_open.png\" /></td><td id=\"td2\">".getMonth($i)."</td>";
	for ($j = 0; $j < count($attributesArray); $j++) {
		$l = $j + 3;
		print "<td id=\"td".$l."\">$result[$j]</td>";
	}
	print "</tr>";
}

?>
</tbody>